﻿
using Dapper;
using HBase;
using hCommand;
using Net.http;
using Persistence;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Transactions;

namespace Persistence {
    /**
   *┌────────────────────────────────────────────────┐
   *│　描    述：Component                                                    
   *│　作    者：sgj                                              
   *│　版    本：1.0                                              
   *│　创建时间：2020/9/2 11:28:16                        
   *└────────────────────────────────────────────────┘
   **/
    public class StatUtil {
        
             
   
 
        public static void changeBatch(Sw sw,List<CoreStockDet> csds) {
            foreach (CoreStockDet csd in csds) {
                if (csd.status==(int)StockDetailStatus.盘亏中) {
                    changeBatch(sw,csd,false);
                } else if (csd.status==(int)StockDetailStatus.盘盈) {
                    changeBatch(sw,csd,true);
                } else {
                    throw new Exception("更新批次信息状态异常"+csd.id);
                }


            }
        }
        public static void changeBatch(Sw sw,CoreStockDet csds,bool add) {
            if (String.IsNullOrEmpty(csds.batchNo)) {
                return;
            } 
            WhBatch batch = new WhBatch();
            batch.batchNo = csds.batchNo;
            batch.itemId = csds.itemId;
            WhBatch b = sw.queryUnique<WhBatch>("select * from wh_batch where batch_No=@batchNo and item_Id=@itemId", batch);
            if (b == null) {
                batch.cv = 1;
                sw.insert(batch); 
            } else {
                sw.exec("update wh_batch set  cv=cv+1 where batch_No  = @batchNo", csds);
            }
         
             
        } 
    }
}
